package watch

//Section 储存Section字段中的key-value组
type Section struct {
	key    map[string]string
	keyNum int
}

//GetValue 根据key得到value
func (sec Section) GetValue(key string) string {
	k := sec.key[key]
	return k
}

//GetKey 得到key的复制
func (sec Section) GetKey() map[string]string {
	k := make(map[string]string)
	for key, value := range sec.key {
		k[key] = value
	}
	return k
}

//GetKeyNum 得到Section中储存的key数目
func (sec Section) GetKeyNum() int {
	return sec.keyNum
}

//ExistKey 判断key是否存在
func (sec Section) ExistKey(key string) bool {
	_, exist := sec.key[key]
	return exist
}

//Equal 判断两个section数值是否相同
func (sec Section) Equal(obj Section) bool {
	if sec.keyNum != obj.keyNum {
		return false
	}

	for key, value := range sec.key {
		if !obj.ExistKey(key) || value != obj.GetValue(key) {
			return false
		}
	}

	return true
}
